package shared.pojo

import shared.Pojo.{DataMatrixData, FsPreprocessData}
import upickle.default._

import scala.collection.immutable.SeqMap
import shared.implicits.Implicits._
import shared.pojo.Pojo.groupFileData
import shared.tool.DefaultPickle

/** Created by yz on 18/10/2022
  */
object WorkflowMission {

  object MissionNameCheck {

    case class Request(id: Int, missionName: String)

    implicit val requestRw = macroRW[Request]
  }

  case class McInfo(
      group: String = "",
      `p.adj`: String = "0.05",
      log2Fc: String = "0"
  )

  object McInfo {
    implicit val rw = macroRW[McInfo]
    implicit val defaultRw = DefaultPickle.macroRW[McInfo]
  }

  case class EachUniAnaData(
      mcInfos: List[McInfo] = List.empty,
      execPostHoc: Boolean = false,
      isInter: String = "F",
      isPaired: Boolean = false,
      method: String = "auto",
      fcMethod: String = "auto",
      pValue: String = "0.05",
      useFdr: Boolean = false,
      fdr: String = "1",
      log2FC: String = "0",
      execTrend: Boolean = false,
      trendMethod: String = "both",
      groups: List[String] = List.empty,
      uniAnaGroups: List[String] = List.empty,
      nodeId: String = ""
  )

  object EachUniAnaData {
    implicit val rw = macroRW[EachUniAnaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachUniAnaData]
  }

  case class EachOplsdaData(
      scaleMethod: String = "scale",
      group: String = "",
      vip: String = "1",
      q2Y: String = "0.2",
      q2YB: String = "0",
      nodeId: String = ""
  )

  object EachOplsdaData {
    implicit val rw = macroRW[EachOplsdaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachOplsdaData]
  }

  case class EachPlsdaData(
      groups: List[String] = List.empty,
      scaleMethod: String = "scale",
      vip: String = "1",
      isPaired: Boolean = false,
      nodeId: String = ""
  )

  object EachPlsdaData {
    implicit val rw = macroRW[EachPlsdaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachPlsdaData]
  }

  case class EachPcaData(
      groups: List[String] = List.empty,
      scaleMethod: String = "scale",
      isPaired: Boolean = false,
      nodeId: String = ""
  )

  object EachPcaData {
    implicit val rw = macroRW[EachPcaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachPcaData]
  }

  case class EachCorData(
      extraFile: String = "",
      hasConfounder: Boolean = false,
      confounderFile: String = "",
      corMethod: String = "pearson",
      fdrMethod: String = "fdr",
      coe: String = "0.5",
      p: String = "0.05",
      fdr: String = "1",
      nodeSize: String = "1",
      nodeId: String = ""
  )

  object EachCorData {
    implicit val rw = macroRW[EachCorData]
    implicit val defaultRw = DefaultPickle.macroRW[EachCorData]
  }

  case class EachPathwayAnaData(
      execIPath: Boolean = true,
      fcMethod: String = "auto",
      libType: String = "smpdb_pathway",
      species1: String = "Mammals",
      species: String = "hsa",
      isSmp: String = "kegg",
      method: String = "hyperg",
      nodeImp: String = "dgr",
      nodeId: String = ""
  )

  object EachPathwayAnaData {
    implicit val rw = macroRW[EachPathwayAnaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachPathwayAnaData]
  }

  case class EachIntersectData(
      nodeId: String = ""
  )

  object EachIntersectData {
    implicit val rw = macroRW[EachIntersectData]
    implicit val defaultRw = DefaultPickle.macroRW[EachIntersectData]
  }

  case class EachRfData(
      scaleMethod: String = "scale",
      groups: List[String] = List.empty,
      ntree: String = "500",
      replace: String = "T",
      hasMtry: Boolean = false,
      mtry: String = "",
      hasNodesize: Boolean = false,
      nodesize: String = "",
      hasMaxnode: Boolean = false,
      maxnode: String = "",
      topM: String = "10",
      nodeId: String = ""
  )

  object EachRfData {
    implicit val rw = macroRW[EachRfData]
    implicit val defaultRw = DefaultPickle.macroRW[EachRfData]
  }

  case class EachSvmData(
      scaleMethod: String = "scale",
      groups: List[String] = List.empty,
      kernel: String = "linear",
      cost: String = "1",
      tolerance: String = "0.001",
      epsilon: String = "0.1",
      gamma: String = "",
      coef0: String = "0",
      degree: String = "3",
      topM: String = "10",
      nodeId: String = ""
  )

  object EachSvmData {
    implicit val rw = macroRW[EachSvmData]
    implicit val defaultRw = DefaultPickle.macroRW[EachSvmData]
  }

  case class EachUnionData(
      nodeId: String = ""
  )

  object EachUnionData {
    implicit val rw = macroRW[EachUnionData]
    implicit val defaultRw = DefaultPickle.macroRW[EachUnionData]
  }

  case class EachBorutaData(
      scaleMethod: String = "scale",
      groups: List[String] = List.empty,
      maxRun: String = "100",
      pValue: String = "0.01",
      nodeId: String = ""
  )

  object EachBorutaData {
    implicit val rw = macroRW[EachBorutaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachBorutaData]
  }

  case class EachDiagnoseAnaData(
      scaleMethod: String = "scale",
      group: String = "",
      hasCv: Boolean = false,
      k: String = "10",
      hasExternal: Boolean = false,
      externalPreprocess: String = "F",
      externalFile: String = "",
      externalGroupFile: String = "",
      runRf: Boolean = false,
      ntree: String = "500",
      replace: String = "T",
      hasMtry: Boolean = false,
      mtry: String = "",
      hasNodesize: Boolean = false,
      nodesize: String = "",
      hasMaxnode: Boolean = false,
      maxnode: String = "50",
      runGb: Boolean = false,
      distribution: String = "multinomial",
      gbNTree: String = "400",
      depth: String = "1",
      fraction: String = "0.5",
      runLr: Boolean = false,
      runSvm: Boolean = false,
      kernel: String = "linear",
      cost: String = "1",
      tolerance: String = "0.001",
      epsilon: String = "0.1",
      gamma: String = "",
      coef0: String = "0",
      degree: String = "3",
      runEn: Boolean = false,
      nodeId: String = ""
  )

  object EachDiagnoseAnaData {
    implicit val rw = macroRW[EachDiagnoseAnaData]
    implicit val defaultRw = DefaultPickle.macroRW[EachDiagnoseAnaData]
  }

  case class FsData(
      missionName: String = "",
      exampleWorkflow: String = "unselected",
      file: String = "",
      groupFile: String = "",
      graphData: String = "",
      preprocess: FsPreprocessData = FsPreprocessData(),
      dataMatrix: DataMatrixData = DataMatrixData(),
      uniAna: List[EachUniAnaData] = List.empty,
      oplsda: List[EachOplsdaData] = List.empty,
      intersect: List[EachIntersectData] = List.empty,
      rf: List[EachRfData] = List.empty,
      svm: List[EachSvmData] = List.empty,
      union: List[EachUnionData] = List.empty,
      boruta: List[EachBorutaData] = List.empty,
      diagnoseAna: List[EachDiagnoseAnaData] = List.empty,
      plsda: List[EachPlsdaData] = List.empty,
      pca: List[EachPcaData] = List.empty,
      cor: List[EachCorData] = List.empty,
      pathwayAna: List[EachPathwayAnaData] = List.empty
  )

  object FsData {
    implicit val rw = macroRW[FsData]
    implicit val defaultRw = DefaultPickle.macroRW[FsData]
  }

  case class ExtraData(
      groups: List[String] = List.empty,
      rowNames: List[String] = List.empty,
      groupHeaders: List[String] = List.empty,
      fileSelectShow: Boolean = false,
      tabs: List[String] = List.empty,
      fileSelect: String => Unit = v => (),
      request: groupFileData.GetAll.Request = groupFileData.GetAll.Request(),
      exampleFileName: String = "",
      canPaired: Boolean = false,
      groupNum:Int=3,
      varInfoRequest:VarInfoFileData.GetAll.Request=VarInfoFileData.GetAll.Request(),
      optionMap:SeqMap[String,String]=SeqMap.empty
  )

  case class ParentNodesData(parentNodes: List[String], showNames: List[String])

  object ParentNodesData {
    implicit val rw = macroRW[ParentNodesData]
    implicit val defaultRw = DefaultPickle.macroRW[ParentNodesData]
  }

  case class FileExistData(missionId: Int, idStr: String, fileName: String)

  object FileExistData {
    implicit val rw = macroRW[FileExistData]
    implicit val defaultRw = DefaultPickle.macroRW[FileExistData]
  }


  case class InputMetabolitesRq(missionId: Int, idStr: String)

  object InputMetabolitesRq {
    implicit val rw = macroRW[InputMetabolitesRq]
  }



}
